import { Component, OnInit, Inject } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material';
import { Validators } from '@angular/forms';
import { confirmPassword } from 'app/modules/base/helper';
import { FormBuilder } from '@angular/forms';
import { HttpClient } from '@angular/common/http';

export interface DialogData {
  animal: string;
  name: string;
}
@Component({
  selector: 'm-add',
  templateUrl: './add.component.html',
  styleUrls: ['./add.component.scss'],
})
export class AddComponent implements OnInit {
  item: any;
  constructor(
    public http: HttpClient,
    public fb: FormBuilder,
    public dialogRef: MatDialogRef<AddComponent>,
    @Inject(MAT_DIALOG_DATA) public data: any,
  ) {
  }

  form = this.fb.group({
    name: ['', Validators.required],
    des: ['', Validators.required],
  });

  onNoClick(): void {
    this.dialogRef.close();
  }

  ngOnInit() {}
  cancel() {
    this.dialogRef.close();
  }
  save() {
    if (!this.form.valid) {
      return;
    }

    this.http
      .post('api/admin/area', {
        ...this.form.value,
        parent_level_struct: this.data.level_struct,
      })
      .subscribe((res) => {
        this.dialogRef.close(true)
      });
  }
}
